upload.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view>
  7. <view style="margin: 40rpx;font-size: 32rpx">
  8. <p style="margin-bottom: 20rpx;">上传链接</p>
  9. <textarea v-model="link_url" style="height: 50px;width: 100%;"
  10. placeholder="请上传正确链接~" />
  11. </view>
  12. <view style="margin: 0 40rpx;">
  13. <p style="margin-bottom: 20rpx;">上传作业数据截图</p>
  14. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  15. @chooseSuccess="ceshiChooseSuccess1">
  16. </htz-image-upload>
  17. <p style="height: 50px;font-size: 32rpx;width: 100%;color: #808090;">上传作业数据截图(直播任务请上传销量截图)
  18. </p>
  19. </view>
  20. <view class="signup">
  21. <button type="default" class="but1" @click="submit()">
  22. 提交作业</button>
  23. </view>
  24. </view>
  25. <!-- <view v-if="onlyShow">
  26. <view style="margin: 20rpx;">
  27. <p>{{link_url}}</p>
  28. <view>
  29. <image :src="imageData" mode="scaleToFill"></image>
  30. </view>
  31. </view>
  32. </view> -->
  33. </view>
  34. </template>
  35. <script>
  36. import mvBar from "@/components/mys_navBar/mysNavBar";
  37. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  38. import getPolicyEncode from '@/components/obs/getPolicy.js';
  39. import getSignature from '@/components/obs/GetSignature.js';
  40. export default {
  41. components: {
  42. mvBar,
  43. htzImageUpload,
  44. },
  45. data() {
  46. return {
  47. onlyShow: false,
  48. navH: getApp().globalData.navHeight,
  49. taskId: "",
  50. link_url: "",
  51. imageData: [],
  52. assignmentStatus: "",
  53. mysNavConfig: {
  54. /* 开启单页显示首页图标 */
  55. isHome: true,
  56. /* 固定导航 */
  57. navFixed: true,
  58. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  59. navTitle: {
  60. text: "上传作业",
  61. color: "",
  62. fontSize: "32rpx", // px upx rpx
  63. fontWeight: "normal", // 100 - 700
  64. },
  65. btnType: "type2",
  66. onLeftClick: '',
  67. /* type2 按钮 */
  68. type2Config: {
  69. // 左图标
  70. leftPath: "/static/img/png2.png",
  71. // 右图标
  72. rightPath: "/static/img/png4.png",
  73. // 圆角
  74. radius: "40rpx",
  75. },
  76. },
  77. }
  78. },
  79. onLoad(options) {
  80. let data = options.textObj.replace(/""/g, "");
  81. data = JSON.parse(decodeURIComponent(data))
  82. this.taskId = data.taskId
  83. this.assignmentStatus = data.assignmentStatus
  84. },
  85. methods: {
  86. submit() {
  87. // 校验
  88. if (this.link_url === "") {
  89. uni.showToast({
  90. title: '请输入正确的发布链接',
  91. icon: 'none'
  92. })
  93. return
  94. }
  95. // if (this.link_url != "" && (this.link_url.substring(0, 8) != "https://" && this.link_url.substring(0, 7) !=
  96. // "http://")) {
  97. // uni.showToast({
  98. // title: '请输入正确的发布链接',
  99. // icon: 'none'
  100. // })
  101. // return
  102. // }
  103. // if (this.imageData.length == 0) {
  104. // uni.showToast({
  105. // title: '请上传收录/发布截图',
  106. // icon: 'none'
  107. // })
  108. // return
  109. // }
  110. let that = this
  111. uni.showModal({
  112. title: '提示',
  113. content: '提交后无法修改并进行审核,确认提交?',
  114. success: async function(res) {
  115. if (res.confirm) {
  116. // 调用添加链接接口
  117. await that.addAssignmentApi()
  118. uni.navigateBack()
  119. } else if (res.cancel) {
  120. console.log('用户点击取消');
  121. }
  122. }
  123. });
  124. },
  125. addAssignmentApi() {
  126. return this.$https.post('/youngee/c/api/t/assignment/add', {
  127. task_id: this.taskId,
  128. link_url: this.link_url,
  129. photo_url: this.imageData[0],
  130. })
  131. .then(res => {})
  132. },
  133. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  134. console.log('ceshiChooseSuccess', tempFilePaths, e);
  135. if (e == 0) {
  136. this.store = 'talent_upload/' + this.guid() + '.png'
  137. } else if (e == 1) {
  138. this.store = 'talent_upload/' + this.guid() + '.mp4'
  139. }
  140. /****************
  141. 以下代码是自定义上传逻辑,仅供参考
  142. ***************/
  143. this.imgUpload1(tempFilePaths);
  144. /*******************************/
  145. console.log("imgdata" + this.imageData)
  146. },
  147. imgUpload1(tempFilePaths) {
  148. let that = this
  149. console.log('imgUpload', tempFilePaths)
  150. let config = {
  151. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  152. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  153. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  154. };
  155. let fileName = this.store; //指定上传到OBS桶中的对象名
  156. // let fileName = "talent_upload/icon-arrow-right.png"
  157. let OBSPolicy = { //设定policy内容
  158. "expiration": "2089-12-31T12:00:00.000Z",
  159. "conditions": [{
  160. "bucket": "horastar"
  161. }, //Bucket name
  162. // {"bucket": "goin"},
  163. {
  164. 'key': fileName
  165. }
  166. ]
  167. }
  168. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  169. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  170. uni.uploadFile({
  171. //url: config.EndPoint,
  172. url: config.EndPoint,
  173. filePath: tempFilePaths[0],
  174. name: 'file',
  175. formData: {
  176. 'AccessKeyID': config.AccessKeyId,
  177. 'policy': policyEncoded,
  178. 'signature': signature,
  179. 'key': fileName,
  180. },
  181. success: function(res) {
  182. console.log(res.statusCode); //打印响应状态码
  183. if (res.statusCode == '204') {
  184. that.imageData.push(config.EndPoint + '/' + fileName);
  185. console.log('上传图片成功', res)
  186. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  187. console.log(obs_url)
  188. // that.formData.home_img = obs_url
  189. uni.showToast({
  190. title: '上传成功',
  191. icon: '成功'
  192. });
  193. } else {
  194. console.log('上传图片失败', res)
  195. uni.showToast({
  196. title: '上传失败',
  197. icon: '失败'
  198. });
  199. }
  200. },
  201. fail: function(e) {
  202. console.log(e);
  203. uni.showToast({
  204. title: '上传失败',
  205. icon: '失败'
  206. });
  207. }
  208. })
  209. },
  210. guid() {
  211. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  212. var r = Math.random() * 16 | 0,
  213. v = c == 'x' ? r : (r & 0x3 | 0x8);
  214. return v.toString(16);
  215. });
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .signup {
  222. box-shadow: 0rpx 5rpx 40rpx #ccc;
  223. width: 100%;
  224. position: fixed;
  225. bottom: 0rpx;
  226. display: flex;
  227. height: 90rpx;
  228. padding-top: 2%;
  229. background-color: #FFFFFF;
  230. }
  231. .but1 {
  232. width: 60%;
  233. background-color: #f2d22d;
  234. border-radius: 20rpx;
  235. font-size: 36rpx;
  236. line-height: 200%;
  237. letter-spacing: 10rpx;
  238. font-weight: 500;
  239. height: 80%;
  240. &.on {
  241. background-color: #C0C0C0;
  242. }
  243. }
  244. </style>