uploadsketch.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()" style="margin-bottom:20rpx">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 32rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view v-if="!loading && !onlyShow">
  15. <view style="display: flex;justify-content: center;">
  16. <radio-group @change="chan">
  17. <label v-for="item in radioGroup" :key="item">
  18. <view style="display: inline;margin: 0 20rpx">
  19. <radio :value="item" :checked="item==activeRadio" color="#fdd544" />{{item}}
  20. </view>
  21. </label>
  22. </radio-group>
  23. </view>
  24. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '图文'">
  25. <htz-image-upload :max="18" mediaType="image" name="file" :chooseNum="9" v-model="imageData"
  26. @chooseSuccess="ceshiChooseSuccess1">
  27. </htz-image-upload>
  28. </view>
  29. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '视频'">
  30. <htz-image-upload :max="1" mediaType="video" name="file" :chooseNum="1" v-model="videoData"
  31. @chooseSuccess="ceshiChooseSuccess2">
  32. </htz-image-upload>
  33. </view>
  34. <uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧"
  35. :placeholderStyle="placeholderStyle">
  36. </uni-easyinput>
  37. <!-- 多行输入框 -->
  38. <view style="padding: 40rpx 30rpx 150rpx;font-size: 12px">
  39. <textarea v-model="text" maxlength="2000" auto-height="true" placeholder="添加正文" />
  40. </view>
  41. <view class="signup">
  42. <button type="default" class="but1" :loading="loading" :class="{'on':item.title == '1',}"
  43. @click="submit()">
  44. 提交初稿</button>
  45. </view>
  46. </view>
  47. <view v-if="!loading && onlyShow">
  48. <view style="margin: 20rpx; 50rpx">
  49. <!-- 图文 -->
  50. <view style="display: flex;" v-if="activeRadio == '图文'">
  51. <view v-for="photo in imageData">
  52. <image :src="photo" mode="aspectFill" style="width: 150rpx;height: 150rpx;"></image>
  53. </view>
  54. </view>
  55. <!-- 视频 -->
  56. <view style="display: flex;" v-if="activeRadio == '视频'">
  57. <video :src="videoData[0]"></video>
  58. </view>
  59. <p style="font-size: 16px">{{title}}</p>
  60. <text style="font-size: 12px">{{text}}</text>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import mvBar from "@/components/mys_navBar/mysNavBar";
  67. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  68. import getPolicyEncode from '@/components/obs/getPolicy.js';
  69. import getSignature from '@/components/obs/GetSignature.js';
  70. export default {
  71. components: {
  72. mvBar,
  73. htzImageUpload,
  74. },
  75. data() {
  76. return {
  77. onlyShow: false,
  78. loading: true,
  79. placeholderStyle: "font-size:16px",
  80. navH: getApp().globalData.navHeight,
  81. taskId: "",
  82. title: "",
  83. text: "",
  84. sketchStatus: "",
  85. activeRadio: '图文', //存的是选中的value值
  86. radioGroup: ['图文', '视频'],
  87. videoData: [],
  88. imageData: [],
  89. mysNavConfig: {
  90. /* 开启单页显示首页图标 */
  91. isHome: true,
  92. /* 固定导航 */
  93. navFixed: true,
  94. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  95. navTitle: {
  96. text: "上传初稿",
  97. color: "",
  98. fontSize: "32rpx", // px upx rpx
  99. fontWeight: "normal", // 100 - 700
  100. },
  101. btnType: "type2",
  102. onLeftClick: '',
  103. /* type2 按钮 */
  104. type2Config: {
  105. // 左图标
  106. leftPath: "/static/img/png2.png",
  107. // 右图标
  108. rightPath: "/static/img/png4.png",
  109. // 圆角
  110. radius: "40rpx",
  111. },
  112. },
  113. }
  114. },
  115. onLoad(options) {
  116. let data = options.textObj.replace(/""/g, "");
  117. data = JSON.parse(decodeURIComponent(data))
  118. this.taskId = data.taskId
  119. this.sketchStatus = data.sketchStatus
  120. this.getSketch()
  121. },
  122. methods: {
  123. chan(e) {
  124. this.activeRadio = e.detail.value;
  125. console.log(this.activeRadio);
  126. },
  127. async getSketch() {
  128. this.loading = true
  129. uni.showLoading({
  130. title: '加载中'
  131. });
  132. await this.$https.get('/youngee/c/t/g/get-unsubmit-task-sketch' +
  133. "?" +
  134. "task_id" +
  135. "=" +
  136. this.taskId)
  137. .then(res => {
  138. console.log(res)
  139. if (res.data.data != null) {
  140. this.onlyShow = true
  141. this.title = res.data.data.title
  142. this.text = res.data.data.content
  143. if (res.data.data.type == 1) { // 图文
  144. this.activeRadio = '图文'
  145. for (var j = 0; j < res.data.data.Photo.length; j++) {
  146. this.imageData.push(res.data.data.Photo[j].photo_url)
  147. }
  148. } else if (res.data.data.type == 2) { //视频
  149. this.activeRadio = '视频'
  150. for (var j = 0; j < res.data.data.Photo.length; j++) {
  151. this.videoData.push(res.data.data.Photo[j].photo_url)
  152. }
  153. }
  154. }
  155. })
  156. uni.hideLoading();
  157. this.loading = false
  158. },
  159. toRecord() {
  160. var data = {
  161. taskId: this.taskId,
  162. };
  163. data = JSON.stringify(data)
  164. uni.navigateTo({
  165. url: '/pages/workspace/sketchrecord?textObj=' + encodeURIComponent(data)
  166. });
  167. },
  168. submit() {
  169. // 检验标题和内容是否为空
  170. let type = 0
  171. let photourl = []
  172. if (this.activeRadio == '图文') { // 图文
  173. type = 1
  174. photourl = this.imageData
  175. } else {
  176. type = 2
  177. photourl = this.videoData
  178. }
  179. if (photourl.length == 0) {
  180. uni.showToast({
  181. title: "请上传初稿图片或视频",
  182. icon: 'none'
  183. })
  184. return
  185. }
  186. if (type === 1) {
  187. if (this.title == '') {
  188. uni.showToast({
  189. title: "请填写初稿标题",
  190. icon: 'none'
  191. })
  192. return
  193. }
  194. if (this.text == '') {
  195. uni.showToast({
  196. title: "请填写初稿内容",
  197. icon: 'none'
  198. })
  199. return
  200. }
  201. }
  202. console.log("photourl:", photourl)
  203. let that = this
  204. uni.showModal({
  205. title: '提示',
  206. content: '提交后无法修改并进行审核,确认提交?',
  207. success: async function(res) {
  208. if (res.confirm) {
  209. await that.$https.post('/youngee/c/t/p/add-task-sketch', {
  210. task_id: that.taskId,
  211. title: that.title,
  212. content: that.text,
  213. type: type,
  214. photo_url: photourl.toString()
  215. })
  216. .then(res => {
  217. console.log(res)
  218. })
  219. await that.$https.get('/youngee/c/t/g/submit-task-sketch' +
  220. "?" +
  221. "task_id" +
  222. "=" +
  223. that.taskId)
  224. .then(res => {
  225. console.log(res)
  226. })
  227. uni.navigateBack()
  228. } else if (res.cancel) {
  229. console.log('用户点击取消');
  230. }
  231. }
  232. });
  233. },
  234. ceshiChooseSuccess1(tempFilePaths, e) { //选择图文返回
  235. console.log('ceshiChooseSuccess', tempFilePaths, e);
  236. /****************
  237. 以下代码是自定义上传逻辑,仅供参考
  238. ***************/
  239. this.imgUpload1(tempFilePaths, e);
  240. /*******************************/
  241. console.log("imgdata" + this.imageData)
  242. },
  243. imgUpload1(tempFilePaths, e) {
  244. let that = this
  245. console.log('imgUpload', tempFilePaths)
  246. let config = {
  247. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  248. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  249. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  250. };
  251. for (let i = 0; i < tempFilePaths.length; ++i) {
  252. if (e == 0) {
  253. this.store = 'talent_upload/' + this.guid() + '.png'
  254. } else if (e == 1) {
  255. this.store = 'talent_upload/' + this.guid() + '.mp4'
  256. }
  257. let fileName = this.store; //指定上传到OBS桶中的对象名
  258. let OBSPolicy = { //设定policy内容
  259. "expiration": "2089-12-31T12:00:00.000Z",
  260. "conditions": [{
  261. "bucket": "horastar"
  262. }, //Bucket name
  263. // {"bucket": "goin"},
  264. {
  265. 'key': fileName
  266. }
  267. ]
  268. }
  269. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  270. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  271. uni.uploadFile({
  272. //url: config.EndPoint,
  273. url: config.EndPoint,
  274. filePath: tempFilePaths[i],
  275. name: 'file',
  276. formData: {
  277. 'AccessKeyID': config.AccessKeyId,
  278. 'policy': policyEncoded,
  279. 'signature': signature,
  280. 'key': fileName,
  281. },
  282. success: function(res) {
  283. console.log(res.statusCode); //打印响应状态码
  284. if (res.statusCode == '204') {
  285. that.imageData.push(config.EndPoint + '/' + fileName);
  286. console.log('上传图片成功', res)
  287. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  288. console.log(obs_url)
  289. // that.formData.home_img = obs_url
  290. uni.showToast({
  291. title: '上传成功',
  292. icon: '成功'
  293. });
  294. } else {
  295. console.log('上传图片失败', res)
  296. uni.showToast({
  297. title: '上传失败',
  298. icon: '失败'
  299. });
  300. }
  301. },
  302. fail: function(e) {
  303. console.log(e);
  304. uni.showToast({
  305. title: '上传失败22222',
  306. icon: '失败'
  307. });
  308. }
  309. })
  310. }
  311. },
  312. ceshiChooseSuccess2(tempFilePaths, e) { //选择视频返回
  313. console.log('ceshiChooseSuccess', tempFilePaths, e);
  314. if (e == 0) {
  315. this.store = 'talent_upload/' + this.guid() + '.png'
  316. } else if (e == 1) {
  317. this.store = 'talent_upload/' + this.guid() + '.mp4'
  318. }
  319. /****************
  320. 以下代码是自定义上传逻辑,仅供参考
  321. ***************/
  322. this.imgUpload2(tempFilePaths);
  323. /*******************************/
  324. console.log("videoData" + this.videoData)
  325. },
  326. imgUpload2(tempFilePaths) {
  327. let that = this
  328. console.log('videoUpload', tempFilePaths)
  329. let config = {
  330. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  331. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  332. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  333. };
  334. let fileName = this.store; //指定上传到OBS桶中的对象名
  335. // let fileName = "talent_upload/icon-arrow-right.png"
  336. let OBSPolicy = { //设定policy内容
  337. "expiration": "2089-12-31T12:00:00.000Z",
  338. "conditions": [{
  339. "bucket": "horastar"
  340. }, //Bucket name
  341. // {"bucket": "goin"},
  342. {
  343. 'key': fileName
  344. }
  345. ]
  346. }
  347. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  348. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  349. uni.uploadFile({
  350. //url: config.EndPoint,
  351. url: config.EndPoint,
  352. filePath: tempFilePaths[0],
  353. name: 'file',
  354. formData: {
  355. 'AccessKeyID': config.AccessKeyId,
  356. 'policy': policyEncoded,
  357. 'signature': signature,
  358. 'key': fileName,
  359. },
  360. success: function(res) {
  361. console.log(res.statusCode); //打印响应状态码
  362. if (res.statusCode == '204') {
  363. that.videoData.push(config.EndPoint + '/' + fileName);
  364. console.log('上传图文成功', res)
  365. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  366. console.log(obs_url)
  367. // that.formData.home_img = obs_url
  368. uni.showToast({
  369. title: '上传成功',
  370. icon: '成功'
  371. });
  372. } else {
  373. console.log('上传图文失败', res)
  374. uni.showToast({
  375. title: '上传失败',
  376. icon: '失败'
  377. });
  378. }
  379. },
  380. fail: function(e) {
  381. console.log(e);
  382. uni.showToast({
  383. title: '上传失败22222',
  384. icon: '失败'
  385. });
  386. }
  387. })
  388. },
  389. guid() {
  390. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  391. var r = Math.random() * 16 | 0,
  392. v = c == 'x' ? r : (r & 0x3 | 0x8);
  393. return v.toString(16);
  394. });
  395. },
  396. },
  397. }
  398. </script>
  399. <style lang="scss" scoped>
  400. .signup {
  401. box-shadow: 0rpx 5rpx 40rpx #ccc;
  402. width: 100%;
  403. position: fixed;
  404. bottom: 0rpx;
  405. display: flex;
  406. height: 90rpx;
  407. padding-top: 2%;
  408. background-color: #FFFFFF;
  409. z-index: 99;
  410. }
  411. .but1 {
  412. width: 60%;
  413. background-color: #f2d22d;
  414. border-radius: 20rpx;
  415. font-size: 36rpx;
  416. line-height: 200%;
  417. letter-spacing: 10rpx;
  418. font-weight: 500;
  419. height: 80%;
  420. &.on {
  421. background-color: #C0C0C0;
  422. }
  423. }
  424. </style>